﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Simple_CommandID_Server
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            leetSocket1.startListening();
        }

        private void leetSocket1_OnReceiveCompletedDataEVENT(object value, byte[] bArray)
        {
            //invoke is required because the socket system works in a separate thread. 
            //Therefore invoking this method in gui thread with the help of the method invoke,
            //allows us to manipulate gui objects, see for further explanation msdn, or google
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new MethodInvoker(delegate() { leetSocket1_OnReceiveCompletedDataEVENT(value, bArray); }));
                return;
            }

            byte commandID = bArray[0];

            switch (commandID)
            {
                case 100:
                    {
                        Boolean b = (Boolean)value;
                        checkBox1.Checked = b;
                        break;
                    }

                case 123:
                    {
                        String s = (String)value;
                        textBox1.Text = s;
                        break;
                    }
            }
        }
    }
}
